package com.guo.redis.business.hello.controller;

import com.guo.redis.business.hello.service.IDistributeLockService;
import com.guo.redis.business.hello.service.StockCounterService;
import com.guo.redis.config.lock.LockValueContainer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.ThreadLocalRandom;

/**
 * 测试用Controller
 *
 * @author H2014046
 * 2021/6/22 下午 03:28
 */
@RestController
@RequestMapping("/hello")
@Slf4j
public class HelloController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/world")
    public String helloWorld() {
        return "Hello World!";
    }

    @RequestMapping("/saveKey")
    public String saveValue(String value) {
        stringRedisTemplate.opsForValue().set("hello", value);
        return "success";
    }

    @RequestMapping("/getKey")
    public String getKey() {
        return stringRedisTemplate.opsForValue().get("hello");
    }


    @RequestMapping("/increment")
    public String increment(String key) {
        Assert.notNull(key,"key 不可为空");
        Long formId = stringRedisTemplate.opsForValue().increment(key);
        return "formId: " + formId;
    }




}
